package com.ningmengs789.live.live.live.common.widget.red;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ningmengs789.live.R;
import com.ningmengs789.live.live.live.common.widget.gift.AbsDialogFragment;
import com.ningmengs789.live.live.live.play.TCLivePlayerActivity;
import com.ningmengs789.live.live.live.push.TCLiveBasePublisherActivity;


public class RPResultsDialogFragment extends AbsDialogFragment {

    private View mContentView;

    private String name;
    private String mBonusId;
    private String avatar;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_robrp_item_23;
    }

    @Override
    protected int getDialogStyle() {
        return R.style.BottomDialog2;
    }

    @Override
    protected boolean canCancel() {
        return true;
    }

    @Override
    protected void setWindowAttributes(Window window) {
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle == null) {
            return;
        }
        mBonusId = bundle.getString("bonus_id");
        avatar = bundle.getString("avatar");
        name = bundle.getString("name");

        String status = bundle.getString("status");
        String money = bundle.getString("money");

        if (status.equals("1")){//1成功抢到 2没抢到
            mContentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_robrp_item_3, (ViewGroup) mRootView, false);
            TextView describe = mContentView.findViewById(R.id.describe);
            describe.setText("抢到" + name + "的红包");
            TextView moneyTV = mContentView.findViewById(R.id.money);
            moneyTV.setText(money);
        }else {
            mContentView = LayoutInflater.from(mContext).inflate(R.layout.dialog_robrp_item_2, (ViewGroup) mRootView, false);
            TextView describe = mContentView.findViewById(R.id.describe);
            describe.setText("你未抢到" + name + "的红包");
        }

        mContentView.findViewById(R.id.history).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mContext instanceof TCLivePlayerActivity){
                    ((TCLivePlayerActivity)mContext).historyRP(mBonusId, avatar, name);
                }else if (mContext instanceof TCLiveBasePublisherActivity){
                    ((TCLiveBasePublisherActivity)mContext).historyRP(mBonusId, avatar, name);
                }
                dismiss();
            }
        });

        if (mRootView != null && mContentView != null) {
            ((ViewGroup) mRootView).addView(mContentView);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
